//解构赋值：按照一定的规则，从数组或对象中取值，给声明变量赋值


//数组：下标

//对象: key

//前端post get

// let {username,age} = this.ctx.request.body; //{username:,age:}

// let {limit,pagenum} = this.ctx.query;  //{limit,pagenum}

//1.给默认值=  起别名:

let {limit:l=10} = {};

console.log(l);

//2.函数参数

function ajax({type='get',data}){
    // let {type,data} = option;

    // let data = option.data
    console.log(type)
}

ajax({
    type:'post',
    data:{}
})

//数组：解构

//不借助第三个变量，交换两个变量的值

let a = 10;
let b = 20;

[a,b] = [b,a];

//a = 20 b = 10

console.log(a,b);

let params = 'name=lili&age=10'; 

//格式化成对象

let arr = params.split('&');

let obj = {};

for(let i = 0;i<arr.length;i++){
    let [key,value] = arr[i].split('=')  //name=lili   age=10
    obj[key] = value;
}

console.log(obj);






